﻿using GameControl;
using QxFramework.Core;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class KeyChangeUI : UIBase
{
    private FuncField func;

    private void Update()
    {
        
        
        foreach(KeyCode k in System.Enum.GetValues(typeof(KeyCode)))
        {
            if (InputManager.Instance.GetKeyDown(k) == false)
            {
                continue;
            }
           // Event e = Event.current;
            if (InputManager.Instance.UseableKeys.Contains(k))
            {
                MessageManager.Instance.Get<ItemFuncEvent>().DispatchMessage(ItemFuncEvent.OnChangeKey, this, new ItemFuncArgs()
                {
                    BelongItemName = func.BelongingItemName,
                    FuncTypeName = func.FuncTypeName,
                    NewKey=k
                }) ;
                AudioControl.Instance.PlaySound("Save");
            }
            else
            {
                UIManager.Instance.Open("DialogWindowUI", 5, args: new DialogWindowUI.DialogWindowUIArg
("注意", $"设置的按键{k}不在可用范围内", null, "确定", () => { }));
            }
            UIManager.Instance.Close(this.gameObject.name);
        }
    }
    public override void OnDisplay(object args)
    {
        base.OnDisplay(args);
        Debug.Assert(args is FuncField);
        func = args as FuncField;
    }
}
